<template>
  <div class="tab-bar-item" @click="itemClick">
    <!-- 注意：不要在插槽上绑定动态属性等，可能会无法生效 -->
    <div v-if="!isActive"><slot name="item-icon"></slot></div>
    <div v-else><slot name="item-icon-active"></slot></div>
    <div :style="activeStyle"><slot name="item-text"></slot></div>
    <!-- <img src="../../assets/img/tabbar/home.png" alt=""> -->
    <!-- <img src="../../assets/img/tabbar/home_active.png" alt=""> -->
    <!-- <div>首页</div> -->
  </div>
</template>

<script>
  export default {
    name: 'TarBarItem',
    props: {
      link: String, // 父子组件通信，将路由信息动态传入
      activeColor: {
        type: String,
        default: '#ff0000'
      }
    },
    data() {
      return {
        // isActive: true
      }
    },
    methods: {
      itemClick() {
        this.$router.replace(this.link);
      }
    },
    computed: {
      isActive() {
        return this.$route.path.indexOf(this.link) !== -1;
      },
      activeStyle() {
        return this.isActive ? {color: this.activeColor} : '';
      }
    }
  }
</script>

<style>
  .tab-bar-item {
    flex: 1;
    height: 49px;
    text-align: center;
    font-size: 14px;
    cursor: pointer;
  }

  .tab-bar-item img {
    width: 24px;
    height: 24px;
    margin-top: 3px;
    margin-bottom: 2px;
    vertical-align: middle;
  }

  /* .active {
    color: #ff0000;
  } */
</style>
